﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Yuebon.Commons.Models;
using Yuebon.Shop.Application;
using Yuebon.Shop.Dtos;
using Yuebon.Shop.IServices;
using Yuebon.Shop.Models;
using Yuebon.WebApi.Controllers;
using Yuebon.WebApi.Models;

namespace Yuebon.WebApi.Areas.Shop.Controllers
{
    /// <summary>
    /// 分销员
    /// </summary>
    [Route("api/Shop/[controller]")]
    [ApiController]
    public class ReferralsController : BusinessApiController<Referrals, IReferralsService>
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="_iService"></param>
        public ReferralsController(IReferralsService _iService) : base(_iService)
        {
        }

        /// <summary>
        /// 根据主键Id获取一个对象信息
        /// </summary>
        /// <param name="id">主键Id</param>
        /// <param name="token">token令牌</param>
        /// <returns></returns>
        [HttpGet("GetById")]
        public override IActionResult GetById(string id, string token)
        {
            CommonResult result = new CommonResult();

            result = CheckToken(token);
            if (result.ErrCode == ErrCode.successCode)
            {
                ReferralsApp referralsApp = new ReferralsApp();
                ReferralsDto info = referralsApp.GetById(id);
                if (info != null)
                {
                    result.ResData = info;
                }
                else
                {
                    result.ErrMsg = ErrCode.err50001;
                    result.ErrCode = "50001";
                }
            }
            return ToJsonContent(result);
        }
    }
}